/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cuong.bean;

import client.entity.Recruitment;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import util.HibernateUtil;

/**
 *
 * @author Admin Windows 8
 */
@ManagedBean
@SessionScoped
public class MSBController {

    /**
     * Creates a new instance of MSBController
     */
    public MSBController() {
    }
    private List<Recruitment> list;

    public void cleanup() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
                .getExternalContext().getSession(true);
        session.removeAttribute("loadJobByIdCategoryBean");

    }

    public void cleanupComboboxSearch() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
                .getExternalContext().getSession(true);
        session.removeAttribute("comboboxSearchBean");
    }
     public void cleanupSearchJobByLevelJob() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
                .getExternalContext().getSession(true);
        session.removeAttribute("searchJobByLevelJob");
    }
     public void cleanupSearchJobByLocale() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
                .getExternalContext().getSession(true);
        session.removeAttribute("searchJobByLocale");
    }
      public void cleanupSearchJobByCategory() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
                .getExternalContext().getSession(true);
        session.removeAttribute("searchJobByCategory");
    }

    public List<Recruitment> getList() {
        //
          SessionFactory factory = HibernateUtil.getSessionFactory();
        Session ss = factory.openSession();
        ss.getTransaction().begin();
       // list=ss.createQuery("select re from Recruitment as re inner join re.recruitmentCategories as c where c.category.id=4").list();
     //   list=ss.createQuery("from Recruitment re order by re.id desc").setMaxResults(10).list();
        list=ss.createQuery("select re from Recruitment as re inner join re.recruitmentCategories as c inner join re.recruitmentLocations as l  where c.category.id=4 and l.location.id=1").list();
       ss.getTransaction().commit();
        ss.close();
        return list;
    }

    public void setList(List<Recruitment> list) {
        this.list = list;
    }
    
}
